using System;
using System.Configuration;
using System.Threading;
using RPW.Simple;

class SampleWorker : ISimpleServiceWorker {
    private int m_frequencyMs = 60000;

    public void Init() {
        // initialize resources here

        try {
            m_frequencyMs = 1000 * Convert.ToInt32(ConfigurationManager.AppSettings["frequencySeconds"]);
        } catch (FormatException e) {
            SimpleService1.WriteLog(e);
        } catch (OverflowException e) {
            SimpleService1.WriteLog(e);
        }

    }

    public void Run() {
        // perform a threaded task here

        while (true) {
            //simulate work
            SimpleService1.WriteLog(string.Format("Timer Event : {0} second frequency", m_frequencyMs), System.Diagnostics.EventLogEntryType.Information);
            Thread.Sleep(m_frequencyMs);
            SimpleService1.WriteLog(string.Format("Timer Event : {0} second frequency", m_frequencyMs), System.Diagnostics.EventLogEntryType.Warning);
            Thread.Sleep(m_frequencyMs);
        }
    }

    public void Cleanup() {
        // cleanup resources here
    }
}